home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / workbench / wbrun.e < prev   
Text File  |  1994-05-02  |  4KB  |  146 lines

  1.  
  2. ENUM ER_NONE,ER_ONLYCLI,ER_BADARGS,ER_PORT,ER_NOPORT,ER_NOINFO
  3.  
  4. MODULE 'exec/ports','exec/nodes','wbmessage'
  5. MODULE 'dos/dostags','dos/dosextens'
  6.  
  7. DEF comm[256]:STRING
  8. DEF stack=4000,pri=0
  9. DEF pro:PTR TO process
  10. PROC main() HANDLE /*"main()"*/
  11.     DEF myargs:PTR TO LONG,rdargs=NIL
  12.     IF wbmessage<>NIL THEN Raise(ER_ONLYCLI)
  13.     myargs:=[0,0,0]
  14.     pro:=FindTask(0)
  15.     IF rdargs:=ReadArgs('Commande/A,S=Stack/N,P=Priorité/N',myargs,NIL)
  16.         StrCopy(comm,myargs[0],ALL)
  17.         IF myargs[1] THEN stack:=Long(myargs[1])
  18.         IF myargs[2] THEN pri:=Long(myargs[2])
  19.         IF stack<4000 THEN stack:=4000
  20.         IF ((pri<-10) OR (pri>10)) THEN pri:=0
  21.         Raise(wb_WBRun(comm,stack,pri))
  22.     ELSE
  23.         Raise(ER_BADARGS)
  24.     ENDIF
  25.     Raise(ER_NONE)
  26. EXCEPT
  27.     IF rdargs THEN FreeArgs(rdargs)
  28.     SELECT exception
  29.         CASE ER_ONLYCLI;    WriteF('Du CLi Uniquement.\n')
  30.         CASE ER_BADARGS;    WriteF('Mauvais argument(s).\n')
  31.         CASE ER_PORT;       WriteF('Impossible de créer le port de message.\n')
  32.         CASE ER_NOPORT;     WriteF('Impossible de trouver le "WBStart-Handler Port".\n')
  33.         CASE ER_NOINFO;     WriteF('Pas d\aicone pour le fichier \s.\n',comm)
  34.     ENDSELECT
  35. ENDPROC
  36. PROC wb_WBRun(com,st,pr) HANDLE /*"wb_WBrun(com,st,pr)"*/
  37.     DEF execmsg:PTR TO mn
  38.     DEF wbsm:wbstartmsg
  39.     DEF rc=FALSE
  40.     DEF node:PTR TO ln
  41.     DEF dummyport:PTR TO mp
  42.     DEF hp
  43.     DEF pv[256]:STRING,flen
  44.     StringF(pv,'\s.info',com)
  45.     IF (flen:=FileLength(pv))=-1 THEN Raise(wb_CLIRun(com))
  46.     IF (dummyport:=CreateMsgPort())=NIL THEN Raise(ER_PORT)
  47.     wbsm:=New(SIZEOF wbstartmsg)
  48.     execmsg:=wbsm
  49.     node:=execmsg
  50.     node.type:=NT_MESSAGE
  51.     node.pri:=0
  52.     execmsg.replyport:=dummyport
  53.     wbsm.name:=com
  54.     wbsm.dirlock:=Lock(com,-2)
  55.     wbsm.stack:=st
  56.     wbsm.prio:=pr
  57.     wbsm.numargs:=0
  58.     wbsm.arglist:=0
  59.     Forbid()
  60.     IF (hp:=FindPort('WBStart-Handler Port'))=NIL  /* THEN Raise(ER_NOPORT)  */
  61.         hp:=wb_InitWBHandler()
  62.     ENDIF
  63.     IF hp
  64.         PutMsg(hp,wbsm)
  65.     ENDIF
  66.     Permit()
  67.     IF hp
  68.         WaitPort(dummyport)
  69.         GetMsg(dummyport)
  70.         rc:=wbsm.stack
  71.     ENDIF
  72.     IF rc=0 THEN WriteF('WBRun Failed.\n')
  73.     Raise(ER_NONE)
  74. EXCEPT
  75.     IF wbsm.dirlock THEN UnLock(wbsm.dirlock)
  76.     IF wbsm THEN Dispose(wbsm)
  77.     IF dummyport THEN DeleteMsgPort(dummyport)
  78.     RETURN exception
  79. ENDPROC
  80. PROC wb_CLIRun(cmd) HANDLE /*"wv_CLIRun(cmd)"*/
  81.     DEF ofh:PTR TO filehandle
  82.     DEF ifh:PTR TO filehandle
  83.     DEF newct=NIL:PTR TO mp
  84.     DEF oldct:PTR TO mp
  85.     DEF oldcd
  86.     DEF newcd
  87.     DEF er,cli:PTR TO commandlineinterface
  88.     IF ofh:=Open('NIL:',1006)
  89.         IF IsInteractive(ofh)
  90.             WriteF('IsInteractive Ok\n')
  91.             newct:=ofh.type
  92.             oldct:=SetConsoleTask(newct)
  93.             ifh:=Open('CONSOLE:',1005)
  94.             SetConsoleTask(oldct)
  95.         ELSE
  96.             ifh:=Open('NIL:',1005)
  97.         ENDIF
  98.     ENDIF
  99.     newcd:=Lock(cmd,-2)
  100.     oldcd:=CurrentDir(newcd)
  101.     IF SystemTagList(cmd,[SYS_OUTPUT,stdout,
  102.                          SYS_INPUT,pro.cis,
  103.                          SYS_ASYNCH,FALSE,
  104.                          SYS_USERSHELL,FALSE,
  105.                          NP_STACKSIZE,4000,
  106.                          NP_PRIORITY,0,
  107.                          NP_PATH,NIL,
  108.                          NP_CONSOLETASK,newct,
  109.                          NP_CLI,conout,
  110.                          0])
  111.         er:=IoErr()
  112.     ENDIF
  113.     cli:=stdout
  114.     WriteF('Error \d \d \d\n',er,pro.result2,cli.returncode)
  115.     CurrentDir(oldcd)
  116.     IF ofh THEN Close(ofh)
  117.     IF ifh THEN Close(ifh)
  118.     Raise(ER_NONE)
  119. EXCEPT
  120.     RETURN exception
  121. ENDPROC
  122. PROC wb_InitWBHandler() HANDLE /*"wb_InitWBHandler()"*/
  123.     DEF ifh
  124.     DEF ofh
  125.     DEF wbh
  126.     IF (ifh:=Open('NIL:',1006))=NIL THEN Raise(NIL)
  127.     IF (ofh:=Open('NIL:',1005))=NIL THEN Raise(NIL)
  128.     SystemTagList('L:WBStart-Handler',[SYS_INPUT,ifh,
  129.                                       SYS_OUTPUT,ofh,
  130.                                       SYS_ASYNCH,TRUE,
  131.                                       SYS_USERSHELL,TRUE,
  132.                                       NP_CONSOLETASK,NIL,
  133.                                       NP_WINDOWPTR,NIL])
  134.     Delay(25)
  135.     wbh:=FindPort('WBStart-Handler Port')
  136.     Raise(wbh)
  137. EXCEPT
  138.     IF Not(wbh)
  139.         IF ifh THEN Close(ifh)
  140.         IF ofh THEN Close(ofh)
  141.     ENDIF
  142.     RETURN wbh
  143. ENDPROC
  144.  
  145.  
  146.